package com.power.flowable.api;

import com.plf.common.domain.ResponseDTO;
import com.power.flowable.model.pageinfo.FlowablePageInfo;
import com.power.flowable.model.pageinfo.ProcessDefinitionPageInfo;
import feign.Response;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.lang.reflect.InvocationTargetException;

/**
 * 流程定义相关接口
 * @author wangning
 *
 */

@FeignClient(value = "sfflow-svr", contextId = "sfflow-svr", path = "/sfflow-svr")
@RestController
public interface IProcessDefFeign {

	/**
	 * 查询已定义的流程列表
	 * @param tenantid
	 * @param pageinfo
	 * @return List已定义流程列表
	 */
	@PostMapping("flow/processList")
	ResponseDTO processList(@RequestParam(required = false)String tenantid, @RequestBody ProcessDefinitionPageInfo pageinfo);

	/**
	 * 上传流程文件进行发布
	 * @param file
	 * @param tenantid 租户id
	 * @return
	 */
	@PostMapping("flow/processSave")
	ResponseDTO processSave(@RequestParam(required = false) String tenantid, MultipartFile file);

	/**
	 * 下载流程文件进行发布
	 * @param modelKey
	 * @param tenantid 租户id
	 * @return InputStream 字节流对象
	 */
	@PostMapping("flow/processPublish")
	ResponseDTO processPublish(@RequestParam(required = false) String tenantid,@RequestParam String modelKey);

	/**
	 * 删除流程定义
	 * @param deploymentId 流程部署id (对应act_re_procdef表的deployment_id_字段)
	 * @return
	 */
	@PostMapping("flow/processRemove")
	ResponseDTO processRemove(@RequestParam String deploymentId);

	/**
	 * 查看流程设计图
	 * @param processdefinitionid 流程定义id(对应act_re_procdef表的ID_字段)
	 * @throws Exception
	 */
	@PostMapping(value = "flow/viewDiagram")
	Response viewDiagram(@RequestParam(required = true) String processdefinitionid)  throws Exception;

	/**
	 * 流程部署的停用和启用
	 * @param processdefinitionid 流程定义id(对应act_ru_task表的PROC_DEF_ID_字段)
	 * @param suspensionState 1停用 2启用
	 * @return
	 */
	@PostMapping(value = "flow/suspendOrActivateProcessDefinition")
	ResponseDTO suspendOrActivateProcessDefinition(@RequestParam String processdefinitionid, @RequestParam Integer suspensionState);

	/**
	 * 查询历史流程定义
	 * @param processDefinitionKey
	 */
	@PostMapping(value = "flow/historyProcessList")
	ResponseDTO historyProcessList(@RequestParam String processDefinitionKey, @RequestBody FlowablePageInfo pageinfo);

	/**
	 * 查询流程上或下环节的信息
	 * @param taskid 任务id
	 * @param direction -1 上一环节, 1下一环节
	 * @return
	 * @throws InvocationTargetException
	 * @throws IllegalAccessException
	 */
	@PostMapping(value = "flow/findBehindTaskExecuser")
	ResponseDTO findBehindTaskExecuser(@RequestParam String taskid, @RequestParam Integer direction);

	/**
	 * 查询已发布的流程模型用户节点列表
	 * @param processdefinitionid 流程定义id(对应act_ru_task表的PROC_DEF_ID_字段)
	 * @return
	 */
	@PostMapping(value = "flow/findDefinitionNodeList")
	ResponseDTO findDefinitionNodeList(@RequestParam String processdefinitionid);

	/**
	 * 查询未发布的流程模型用户节点列表
	 * @param modelKey (模型key，对应act_de_model表的model_key字段)
	 * @return
	 */
	@PostMapping(value = "flow/findUnpublishedNodeList")
	ResponseDTO findUnpublishedNodeList(@RequestParam String modelKey);

	/**
	 *  查看未发布流程模型的流程设计图
	 * @param modelKey (模型key，对应act_de_model表的model_key字段)
	 */
	@PostMapping(value = "flow/viewUnpublishedDiagram")
	Response viewUnpublishedDiagram(@RequestParam(required = true) String modelKey);

	/**
	 * 上传流程模型比较变更
	 * @param file
	 * @param modelKey
	 * @return
	 */
	@PostMapping(value = "flow/diagramContrast")
	ResponseDTO diagramContrast(MultipartFile file, @RequestParam String modelKey);
}
